package counter.until;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cunter.session.Session;

/**
 * Servlet implementation class SessionServlet
 */
@WebServlet("/SessionServlet")
public class SessionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SessionServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	public static void doSession(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		int count;
		if(session.getAttribute("yonghu")==null){
			request.getRequestDispatcher("input.jsp").forward(request, response);
		}
		if(session.getAttribute("counter") == null){
			session.setAttribute("counter",1);
		}else{
			count = (Integer)session.getAttribute("counter");
			count++;
			session.setAttribute("counter",count);
		}
		ServletContext context =request.getServletContext();
		if(context.getAttribute("allcount")!=null){
			int count1 =(Integer)context.getAttribute("allcount");
			count1++;
			context.setAttribute("allcount",count1);
		}else{
			context.setAttribute("allcount", 1);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
